
<!DOCTYPE html>
<html>
<head>[#include "../manage/common/head.html" /]
</head>

<body class="gray-bg">
	<div class="wrapper wrapper-content">
		<div class="row">
			<div class="col-sm-12">
				<div class="ibox float-e-margins">
					<div class="ibox-title">
						<h5>退款管理</h5>
					</div>
					<div class="ibox-content">
						<div role="form" class="form-inline">
                            <div class="form-group col-sm-12">
                            	<label class="control-label pull-left">确认退款状态：</label>
								<div class="col-sm-8">
									<select id="isRefundSelect" class="selectpicker show-tick form-control" data-live-search="false">
										<option value="-1"></option>
										<option value="0">未确认</option>
										<option value="1">驳回退款请求</option>
										<option value="2">同意退款请求</option>
									</select>
								</div>
                            </div>
                            <br>
                            <br>
                            <div class="input-search text-center">
	                            <div class="form-group has-feedback input-group">
	                       			<span class="input-group-btn">
							        	<button class="btn btn-primary" type="button" onclick="search();">查询</button>
							     	</span>
	                            </div>
                            </div>
                        </div>
                        <hr>
						<table
							class="table table-striped table-bordered table-hover dataTables">
							<thead>
								<tr>
									<th class="text-center">订单编码</th>
									<th class="text-center">确认退款状态</th>
									<th class="text-center">操作项</th>
								</tr>
							</thead>
							<tbody>
							</tbody>
						</table>

					</div>
				</div>
			</div>
		</div>
	</div>
	<div class="modal fade" id="windowModal" tabindex="-1" role="dialog"
		aria-hidden="true">
		<div class="modal-dialog modal-lg">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-hidden="true">&times;</button>
					<h4 class="modal-title">新建</h4>
				</div>

				<div class="modal-body">
					<form class="form-horizontal" id="myForm">
						<div class="form-group">
							<label class="col-sm-2 control-label">确认退款状态</label>
							<div class="col-sm-8">
								<select id="isRefund" class="selectpicker show-tick form-control"
									data-live-search="false">
									<option value="-1"></option>
									<option value="0">未确认</option>
									<option value="1">驳回退款请求</option>
									<option value="2">同意退款请求</option>
								</select>
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-2 control-label">退款信息</label>
							<div class="col-sm-8">
								<div id="summernote"></div>
							</div>
						</div>
					</form>
				</div>
				<div class="modal-footer clearfix">
					<div class="form-group col-md-8 col-sm-offset-2 text-center">
						<button type="button" class="btn btn-primary" id="save">保存</button>
					</div>
				</div>
			</div>
		</div>
	</div>
	[#include "../manage/common/js.html" /]
	<script>
	$(function() {
		dt = $('.dataTables').dataTable(
			{
				"ordering" : false,
				"searching" : false,
				"info" : true,
				"bLengthChange" : false,
				"pagingType" : "full_numbers",
				"language" : {
					"lengthMenu" : "每页 _MENU_ 条记录",
					"zeroRecords" : "没有找到记录",
					"info" : "第 _PAGE_ 页 ( 总共 _PAGES_ 页 )",
					"infoEmpty" : "无记录",
					"infoFiltered" : "(从 _MAX_ 条记录过滤)",
					"sEmptyTable" : "表中数据为空",
					"sLoadingRecords" : "载入中...",
					"oPaginate" : {
						"sFirst" : "首页",
						"sPrevious" : "上一页",
						"sNext" : "下一页",
						"sLast" : "末页"
					}
				},
				"serverSide" : true,
				"sAjaxSource" : "${base}/manage/orderInfo/selectOrderRefundList",
				"columns" : [
						{
							"data" : "orderNumber",
							"sWidth" : "45%"
						},
						{
							"data" : "isRefund",
							"sWidth" : "45%",
							"render" : function(data) {
								if (data == 0) {
									return '未确认'
								} else if (data == 1) {
									return '驳回退款请求'
								} else if (data == 2) {
									return '同意退款请求'
								} else
									return "";
							}
						},
						{
							"data" : {
								"id" : "id"
							},
							"sWidth" : "10%",
							"render" : function(data) {
								return '<div class="text-center"><button class="btn btn-info btn-sm" type="button" data-title="编辑" data-toggle="modal" data-target="#windowModal" data-id="'
										+ data.id
										+ '" onclick="edit('
										+ data.id
										+ ')">编辑</button><div>'
							}
						} ],
				"fnServerData" : function(sSource, aoData, fnCallback) {
					aoData.push({ "name": "isRefund", "value": $("#isRefundSelect").val() });
					$.ajax({
						"dataType" : 'json',
						"type" : "POST",
						"url" : sSource,
						"data" : aoData,
						"success" : fnCallback
					});
				}
			});

			$('#summernote').summernote({
				height : 150,
				lang : 'zh-CN',
				fontNames : [ 'Microsoft YaHei', 'DengXian', '新宋体', '黑体' ],
				callbacks : {
					onImageUpload : function(files) {
						var formData = new FormData();
						formData.append('file', files[0]);
						formData.append('imgType', 4);
						$.ajax({
							url : '${base}/manage/upload',//后台文件上传接口
							type : 'POST',
							data : formData,
							dataType : 'json',
							processData : false,
							contentType : false,
							success : function(data) {
								$('#summernote').summernote('insertImage','${base}/' + data.file.path,'img');
							}
						});
					}
				}
			});
		})

		function search() {
			dt.fnFilter();
		}

		function restForm() {
			$("#isRefund").val("");
			$('#summernote').summernote('code', "");
		}

		var oid = 0;
		$('#windowModal').on(
				'show.bs.modal',
				function(event) {
					var button = $(event.relatedTarget);
					var recipient = button.data('title');
					var modal = $(this);
					modal.find('.modal-title').text(recipient);
					if (recipient == "编辑") {
						$.post("${base}/manage/orderInfo/getOrderInfo/"
								+ button.data('id'), function(r) {
							oid = r.infoDate.id;
						}, 'json')
					} else {
						oid = 0;
					}
				});

		$("#windowModal").on("hidden.bs.modal", function() {
			restForm();
		});

		$("#save").click(function() {
			var isRefund = $("#isRefund").val().trim();
			if (isRefund == "") {
				swal("警告", "请选择确认退款状态！", "warning");
				return;
			}
			
			var refundMessage = $('#summernote').summernote('code');
			
			$.post("${base}/manage/orderInfo/updateByRefund", {
				id : oid,
				isRefund : isRefund,
				refundMessage : refundMessage
			}, function(r) {
				if (r.code == 0) {
					swal("成功", "保存完成！", "success");
					$('#windowModal').modal('hide');
					search();
				} else {
					swal("错误", r.msg, "error");
				}
			}, 'json')
		})

		function edit(id) {
			$.post("${base}/manage/orderInfo/getOrderInfo/"+id,function(r){
				$("#isRefund").val(r.orderInfoDate.isRefund);
				$('#summernote').summernote('code', r.orderInfoDate.refundMessage);
				oid = id;
			},'json')
		}
	</script>
</body>
</html>
